package com.easylinkin.linkappapi.quality.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.json.JSONUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.easylinkin.linkappapi.common.exceptions.BusinessException;
import com.easylinkin.linkappapi.common.service.CommonService;
import com.easylinkin.linkappapi.common.utils.excel.ExcelConstant;
import com.easylinkin.linkappapi.common.utils.excel.ExcelTools;
import com.easylinkin.linkappapi.common.utils.io.OutputStreamUtil;
import com.easylinkin.linkappapi.openapi.dto.EnterpriseQualityMainIndexCount;
import com.easylinkin.linkappapi.quality.dto.ActualMeasureTypeDto;
import com.easylinkin.linkappapi.quality.entity.*;
import com.easylinkin.linkappapi.quality.entity.vo.ActualMeasureItemVo;
import com.easylinkin.linkappapi.quality.entity.vo.ActualMeasureTypeVo;
import com.easylinkin.linkappapi.quality.entity.vo.QualityScreenPageVo;
import com.easylinkin.linkappapi.quality.mapper.*;
import com.easylinkin.linkappapi.quality.service.ActualMeasureTypeService;
import com.easylinkin.linkappapi.quality.service.QualityAppraisingExcellentService;
import com.easylinkin.linkappapi.security.context.LinkappUserContextProducer;
import com.easylinkin.linkappapi.security.entity.LinkappUser;
import com.easylinkin.linkappapi.tenant.dto.LinkappTenantCount;
import com.easylinkin.linkappapi.tenant.dto.LinkappTenantDTO;
import com.easylinkin.linkappapi.tenant.entity.LinkappTenant;
import com.easylinkin.linkappapi.tenant.mapper.LinkappTenantMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.openxml4j.util.ZipSecureFile;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import org.springframework.web.multipart.MultipartFile;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

/**
 * ActualMeasureType表服务实现类
 *
 * @author zhengwen
 * @date 2022/08/30
 */
@Slf4j
@Service("actualMeasureTypeService")
public class ActualMeasureTypeServiceImpl extends ServiceImpl
        <ActualMeasureTypeMapper, ActualMeasureType> implements ActualMeasureTypeService {
    @Resource
    private CommonService commonService;
    @Resource
    private LinkappUserContextProducer linkappUserContextProducer;
    @Resource
    private ActualMeasureItemMapper actualMeasureItemMapper;

    @Resource
    private LinkappTenantMapper tenantMapper;

    @Resource
    private QualityInspectionMapper qualityInspectionMapper;

    @Resource
    private QualityQuestionInfoMapper questionInfoMapper;

    @Resource
    private  QualityAppraisingExcellentMapper qualityAppraisingExcellentMapper;

    @Resource
    private ProblemTypeMapper problemTypeMapper;

    @Override
    public boolean saveOne(ActualMeasureType appQualityActualMeasureType) {
        commonService.setCreateAndModifyInfo(appQualityActualMeasureType);
        // appQualityActualMeasureType.setTenantId(linkappUserContextProducer.getNotNullCurrent().getTenantId());
        validParamRequired(appQualityActualMeasureType);
        validRepeat(appQualityActualMeasureType);
        validParamFormat(appQualityActualMeasureType);
        return save(appQualityActualMeasureType);
    }


    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateOne(ActualMeasureType appQualityActualMeasureType) {
        Assert.notNull(appQualityActualMeasureType.getId(), "id不能为空");
        commonService.setModifyInfo(appQualityActualMeasureType);
        //appQualityActualMeasureType.setTenantId(linkappUserContextProducer.getNotNullCurrent().getTenantId());
        validRepeat(appQualityActualMeasureType);
        validParamFormat(appQualityActualMeasureType);
        return updateById(appQualityActualMeasureType);
    }

    @Override
    public IPage<ActualMeasureType> selectPage(Page page, ActualMeasureType appQualityActualMeasureType) {
        //校验是否有
        LinkappUser linkappUser = linkappUserContextProducer.getNotNullCurrent();
        QueryWrapper<ActualMeasureType> query = new QueryWrapper<>();
        query.eq("tenant_id", linkappUser.getTenantId());
        query.eq("delete_state", 1);
        int count = baseMapper.selectCount(query);
        if (count == 0) {
            //说明项目还没有实测实量库
            //LinkappTenant tenant = tenantMapper.selectById(linkappUser.getTenantId());
            LinkappTenant tenant = tenantMapper.getById(linkappUser.getTenantId());
            commonService.copyActualMeasureTypeItem(tenant);
        }

        appQualityActualMeasureType.setTenantId(linkappUser.getTenantId());
        return baseMapper.selectPage(page, appQualityActualMeasureType);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteByIds(List<Long> idList) {
        //增加迭代删除子集
        List<Long> finIdLs = new ArrayList<Long>();
        if (CollectionUtil.isNotEmpty(idList)) {
            finIdLs.addAll(idList);
            Iterator<Long> it = idList.iterator();
            while (it.hasNext()) {
                Long id = it.next();
                if (id != null) {
                    queryChildType(id, finIdLs);
                }
            }
        }
        return removeByIds(finIdLs);
    }

    /**
     * 迭代查询子集
     * @param d parentid
     * @param idList id集合
     */
    private void queryChildType(Long d, List<Long> finIdLs) {

        List<ActualMeasureType> typeLs = baseMapper.selectByParentId(d);
        if(CollectionUtil.isNotEmpty(typeLs)){
            typeLs.stream().forEach(t->{
                Integer itemType = t.getItemType();
                finIdLs.add(t.getId());
                if(itemType.intValue() != 3){
                    queryChildType(t.getId(),finIdLs);
                }
            });
        }
    }

    @Override
    public void export(ActualMeasureType appQualityActualMeasureType, HttpServletRequest request, HttpServletResponse
            response) {

        IPage<ActualMeasureType> page = selectPage(new Page(0, -1), appQualityActualMeasureType);
        List<ActualMeasureType> records = page.getRecords();
        List
                <ActualMeasureTypeVo> appQualityActualMeasureTypeVos = new ArrayList<>();
        for (ActualMeasureType expert : records) {
            appQualityActualMeasureTypeVos.add(new ActualMeasureTypeVo(expert));
        }

        String keyValue = "名称:name,租户id:tenantId";
        String title = "ActualMeasureType导出数据";
        String fileName = title + ".xls";
        try {
            OutputStream outputStream = OutputStreamUtil
                    .getOutputStream(request, response, fileName);
            ExcelTools.exportExcel(outputStream, keyValue, appQualityActualMeasureTypeVos, ExcelConstant.XLS, title);
            response.flushBuffer();
            outputStream.close();
        } catch (IOException e) {
            log.error("excel导出失败", e);
            throw new RuntimeException("excel导出失败！IOException异常" + e.getMessage());
        } catch (Exception e) {
            log.error("excel导出失败", e);
            throw new RuntimeException("excel导出失败！" + e.getMessage());
        }
    }

    @Override
    public JSONObject excelImport(MultipartFile file) {
        LinkappUser linkappUser = linkappUserContextProducer.getNotNullCurrent();

        JSONObject json = new JSONObject();
        //读取excel文件
        ZipSecureFile.setMinInflateRatio(-1.0d);
        ExcelReader reader = null;
        try {
            reader = ExcelUtil.getReader(file.getInputStream());
            List<Map<String, Object>> readAll = reader.readAll();
            if (CollectionUtil.isNotEmpty(readAll)) {
                readAll.stream().forEach(c -> {
                    initActualMeasureTypeSave(c, linkappUser);
                    //TODO
                    json.put("list", readAll);
                });
            }

        } catch (IOException e) {
            log.error("---Excel数据导入失败，原因：", e.getMessage());
            throw new BusinessException("Excel数据导入异常");
        }

        return json;
    }

    @Override
    public List<ActualMeasureType> enterpriseGetPage(Page page, ActualMeasureTypeVo actualMeasureTypeVo) {
        //校验是否有
        QueryWrapper<ActualMeasureType> query = new QueryWrapper<>();
        query.isNull("tenant_id");
        query.eq("delete_state", 1);
        List<ActualMeasureType> typeList = baseMapper.selectList(query);
        return typeList;
    }

    @Override
    public RestMessage addActualType(ActualMeasureTypeVo actualMeasureTypeVo) {
        Long parentId = actualMeasureTypeVo.getParentId();
        Assert.isTrue(parentId != null, "父级分类为空");

        String name = actualMeasureTypeVo.getName();
        Assert.isTrue(StringUtils.isNotEmpty(name), "名称不能为空");

        ActualMeasureType actualMeasureType = new ActualMeasureType();
        BeanUtil.copyProperties(actualMeasureTypeVo, actualMeasureType, CopyOptions.create().setIgnoreNullValue(true));

        //查询是否存在
        boolean has = checkHasType(actualMeasureType);
        Assert.isTrue(!has, "分类已存在");
        //查询父级分类
        ActualMeasureType parentType = null;
        if (parentId.intValue() == 0) {
            //发布工程
            actualMeasureType.setItemType(1);
            actualMeasureType.setFullName(actualMeasureType.getName() + "/");
            actualMeasureType.setLevel(1);
        } else {
            parentType = baseMapper.selectById(parentId);
            Assert.isTrue(parentType != null, "父级分类不存在");
            Assert.isTrue(parentType.getItemType() != 3, "末级分类不能再建子集分类");

            actualMeasureType.setItemType(parentType.getItemType() + 1);
            actualMeasureType.setFullName(parentType.getFullName() + actualMeasureType.getName() + "/");
            actualMeasureType.setLevel(parentType.getLevel() + 1);
        }

        //补充参数
        actualMeasureType.setCreator("0");
        actualMeasureType.setCreateTime(DateUtil.date());
        actualMeasureType.setModifier(actualMeasureType.getCreator());
        actualMeasureType.setModifyTime(actualMeasureType.getCreateTime());
        actualMeasureType.setDeleteState(1);
        if (actualMeasureType.getSortNo() == null) {
            actualMeasureType.setSortNo(1);
        }
        //插入
        int inNum = baseMapper.insert(actualMeasureType);
        if (inNum == 1) {
            //更新fullId
            if (parentType == null) {
                actualMeasureType.setFullId("/" + actualMeasureType.getId() + "/");
            } else {
                actualMeasureType.setFullId(parentType.getFullId() + actualMeasureType.getId() + "/");
            }
            baseMapper.updateById(actualMeasureType);
        } else {
            return RestBuilders.failureMessage().setMessage("保存失败");
        }
        return RestBuilders.successBuilder().data(actualMeasureType).build();
    }

    /**
     * 校验是否存在分类
     *
     * @param actualMeasureType 分类
     * @return 是否存在
     */
    private boolean checkHasType(ActualMeasureType actualMeasureType) {
        QueryWrapper<ActualMeasureType> qw = new QueryWrapper<>();
        qw.eq("parent_id", actualMeasureType.getParentId());
        qw.eq("name", actualMeasureType.getName());
        qw.eq("delete_state", 1);
        if (StringUtils.isNotBlank(actualMeasureType.getTenantId())) {
            qw.eq("tenant_id", actualMeasureType.getTenantId());
        } else {
            qw.isNull("tenant_id");
        }

        Long id = actualMeasureType.getId();
        if (id != null) {
            qw.ne("id", id);
        }

        int num = baseMapper.selectCount(qw);
        if (num > 0) {
            return true;
        }
        return false;
    }

    @Override
    public RestMessage editActualType(ActualMeasureTypeVo actualMeasureTypeVo) {
        Long id = actualMeasureTypeVo.getId();
        Assert.isTrue(id != null, "ID为空");

        String name = actualMeasureTypeVo.getName();
        Assert.isTrue(StringUtils.isNotEmpty(name), "名称不能为空");

        //查询
        ActualMeasureType actualMeasureType = baseMapper.selectById(id);
        Assert.isTrue(actualMeasureType != null, "分类不存在");

        String oldName = actualMeasureType.getName();

        BeanUtil.copyProperties(actualMeasureTypeVo, actualMeasureType, CopyOptions.create().setIgnoreNullValue(true));

        Long parentId = actualMeasureType.getParentId();

        //查询是否存在
        boolean has = checkHasType(actualMeasureType);
        Assert.isTrue(!has, "分类已存在");

        //查询父级分类
        ActualMeasureType parentType = null;
        if (parentId.intValue() == 0) {
            //发布工程
            actualMeasureType.setItemType(1);
            actualMeasureType.setFullName(actualMeasureType.getName() + "/");
            actualMeasureType.setLevel(1);
        } else {
            parentType = baseMapper.selectById(parentId);
            Assert.isTrue(parentType != null, "父级分类不存在");
            Assert.isTrue(parentType.getItemType() != 3, "末级分类不能再建子集分类");

            actualMeasureType.setItemType(parentType.getItemType() + 1);
            actualMeasureType.setFullName(parentType.getFullName() + actualMeasureType.getName() + "/");
            actualMeasureType.setLevel(parentType.getLevel() + 1);
        }

        //补充参数
        actualMeasureType.setModifier("0");
        actualMeasureType.setModifyTime(DateUtil.date());
        if (actualMeasureType.getSortNo() == null) {
            actualMeasureType.setSortNo(1);
        }

        int upNum = baseMapper.updateById(actualMeasureType);
        if (upNum != 1) {
            return RestBuilders.failureMessage().setMessage("保存失败");
        }

        //还要修改fullName
        updateTypeFullName(actualMeasureType, oldName);

        return RestBuilders.successBuilder().data(actualMeasureType).build();
    }

    @Override
    public RestMessage syncTypeItem(ActualMeasureTypeVo actualMeasureTypeVo) {
        boolean syncAdd = actualMeasureTypeVo.getSyncAdd();
        boolean syncUpdate = actualMeasureTypeVo.getSyncUpdate();
        LinkappUser linkappUser = linkappUserContextProducer.getNotNullCurrent();
        String tenantId = linkappUser.getTenantId();

        LinkappTenant tenant = tenantMapper.getById(linkappUser.getTenantId());
        //查询企业级的分类、包含算法
        ActualMeasureTypeVo paramVo = new ActualMeasureTypeVo();

        List<ActualMeasureTypeDto> enterData = baseMapper.selectTypeDtoList(paramVo);
        if (CollectionUtil.isNotEmpty(enterData)) {
            //项目级
            paramVo.setTenantId(tenantId);
            List<ActualMeasureTypeDto> tenantData = baseMapper.selectTypeDtoList(paramVo);
            if (CollectionUtil.isNotEmpty(tenantData)) {
                //if(syncUpdate){
                    //同步比较
                    syncActualTypeItem(enterData, tenantData, tenant,syncAdd,syncUpdate);
                //}
            } else {
                //直接新增
                if(syncAdd){
                    commonService.copyActualMeasureTypeItem(tenant);
                }
            }
        }

        return RestBuilders.successBuilder().build();
    }

    @Override
    public RestMessage actualMeasureTypeCount(QualityScreenPageVo qualityScreenPageVo) {
        List<Map<String,Object>> mpLs = new ArrayList<>();

        String queryType = qualityScreenPageVo.getQueryType();
        if (StringUtils.isBlank(queryType)) {
            queryType = "7d";
        }
        Date startTime = qualityScreenPageVo.getStartTime();
        Date endTime = qualityScreenPageVo.getEndTime();
        if(startTime == null && endTime == null){
            endTime = DateUtil.endOfDay(DateUtil.date());
        }
        switch(queryType){
            case "30d":
                startTime = DateUtil.beginOfDay(DateUtil.offsetDay(endTime,-29));
                break;
            case "sm":
                startTime = DateUtil.beginOfDay(DateUtil.offsetMonth(endTime,-5));
                break;
            case "7d":
                startTime = DateUtil.beginOfDay(DateUtil.offsetDay(endTime, -6));
                break;
            default:
                break;
        }
        qualityScreenPageVo.setStartTime(startTime);
        qualityScreenPageVo.setEndTime(endTime);

        List<Map<String,Object>> countLs = baseMapper.actualMeasureTypeCount(qualityScreenPageVo);
        if(CollectionUtil.isNotEmpty(countLs)){
            int otherNum = 0;
            Map<String,Object> otherMp = null;
            if(countLs.size() >= 4){
                otherMp = new HashMap<>();
                otherMp.put("finName","其他");
                otherMp.put("num",otherNum);
            }
            for (int i = 0;i < countLs.size();i++){
                Map<String,Object> mp =  countLs.get(i);
                if(i > 4){
                    otherNum += Integer.parseInt(mp.get("num").toString());
                    otherMp.put("num",otherNum);
                }else{
                    mpLs.add(mp);
                }
            }
            if(otherMp != null){
                mpLs.add(otherMp);
            }
        }

        return RestBuilders.successBuilder().data(mpLs).build();
    }

    @Override
    public RestMessage projectDetailRollShow(QualityScreenPageVo qualityScreenPageVo) {
        Map<String,LinkappTenantCount> mpLs = new HashMap<>();
        //先查项目
        IPage<LinkappTenant> page = new Page<>();
        //Page<LinkappTenant> page = new Page<>();
        page.setCurrent(qualityScreenPageVo.getPage());
        page.setSize(qualityScreenPageVo.getSize());
        QueryWrapper<LinkappTenant> tenantQw = new QueryWrapper<>();
        //tenantQw.isNotNull("project_amount");
        tenantQw.like(StringUtils.isNotBlank(qualityScreenPageVo.getProjectName()), "platform_project_name", qualityScreenPageVo.getProjectName());
        tenantQw.orderByDesc("project_amount");
        IPage pageLs = tenantMapper.selectPage(page,tenantQw);
        if (pageLs != null){
            List<LinkappTenant> ls = pageLs.getRecords();
            List<String> tenantIds = new ArrayList<>();
            if(CollectionUtil.isNotEmpty(ls)){
                ls.stream().forEach(t->{
                    tenantIds.add(t.getId());
                    LinkappTenantCount cou = new LinkappTenantCount();
                    BeanUtil.copyProperties(t,cou,CopyOptions.create().setIgnoreNullValue(true));
                    mpLs.put(t.getId(),cou);
                });

                //查检查数据
                List<Map<String,Object>> checkLs = qualityInspectionMapper.countByTenantStatue(tenantIds);
                if(CollectionUtil.isNotEmpty(checkLs)){
                    checkLs.stream().forEach(c->{
                        Object tenantIdObj = c.get("tenantId");
                        Object typeObj = c.get("type");
                        Object numObj = c.get("num");
                        if(tenantIdObj != null){
                            String tenantId = tenantIdObj.toString();
                            LinkappTenantCount ltc = mpLs.get(tenantId);
                            if(ltc != null) {
                                int num = 0;
                                if(numObj != null){
                                    num = Integer.parseInt(numObj.toString());
                                    ltc.setCheckTotalNum(ltc.getCheckTotalNum() + num);
                                }
                                if(typeObj != null){
                                    //3合格，5无需整改
                                    int type = Integer.parseInt(typeObj.toString());
                                    if(type == 3 || type == 5){
                                        ltc.setCheckCloseNum(ltc.getCheckCloseNum() + num);
                                    }
                                }
                            }
                        }

                    });
                }

                //查实测实量数
                List<Map<String, Object>> typeNumLs = baseMapper.countTypeGroupByTeanant(tenantIds);
                if(CollectionUtil.isNotEmpty(typeNumLs)){
                    typeNumLs.stream().forEach(c->{
                        Object tenantIdObj = c.get("tenantId");
                        Object numObj = c.get("num");
                        Object actualTypeOkNumObj = c.get("actualTypeOkNum");
                        Object actualTypeTotalNumObj = c.get("actualTypeTotalNum");
                        if(tenantIdObj != null) {
                            String tenantId = tenantIdObj.toString();
                            LinkappTenantCount ltc = mpLs.get(tenantId);
                            if (ltc != null) {
                                if(actualTypeTotalNumObj != null) {
                                    ltc.setActualTypeTotalNum(Integer.parseInt(actualTypeTotalNumObj.toString()));
                                }
                                if(actualTypeOkNumObj != null) {
                                    ltc.setActualTypeOkNum(Integer.parseInt(actualTypeOkNumObj.toString()));
                                }
                                if(numObj != null){
                                    ltc.setActualTypeCheckNum(Integer.parseInt(numObj.toString()));
                                }
                            }
                        }
                    });
                }
                List<LinkappTenantCount> rels = new ArrayList<>();
                if(CollectionUtil.isNotEmpty(mpLs)){
                    mpLs.values().stream().forEach(s->{
                        int checkCloseNum = s.getCheckCloseNum();
                        int checkTotalNum = s.getCheckTotalNum();
                        if(checkTotalNum != 0){
                            //查检查闭合率
                            double closeRate = NumberUtil.div(checkCloseNum * 100,checkTotalNum,2);
                            s.setCloseRate(closeRate);
                        }
                        int actualTypeOkNum = s.getActualTypeOkNum();
                        int actualTypeTotalNum = s.getActualTypeTotalNum();
                        if(actualTypeTotalNum != 0){
                            //查实测实量合格率
                            double actualOkRate = NumberUtil.div(actualTypeOkNum * 100,actualTypeTotalNum,2);
                            s.setActualOkRate(actualOkRate);
                        }
                        rels.add(s);
                    });
                    List<LinkappTenantCount> finRels = new ArrayList<>();
                    if(CollectionUtil.isNotEmpty(rels)){
                        //reLs转map
                        Map<String,LinkappTenantCount> relsMp = rels.stream().collect(Collectors.toMap(LinkappTenantCount::getId, rcr->rcr));
                        ls.stream().forEach(t->{
                            LinkappTenantCount cou = relsMp.get(t.getId());
                            finRels.add(cou);
                        });
                    }

                    pageLs.setRecords(finRels);
                }

            }
        }

        return RestBuilders.successBuilder().data(pageLs).build();
    }

    @Override
    public RestMessage actualMeasureCountTop(QualityScreenPageVo qualityScreenPageVo) {
        List<Map<String,Object>> mpLs = new ArrayList<>();

        String queryType = qualityScreenPageVo.getQueryType();
        if (StringUtils.isBlank(queryType)) {
            queryType = "7d";
        }
        Date startTime = qualityScreenPageVo.getStartTime();
        Date endTime = qualityScreenPageVo.getEndTime();
        if(startTime == null && endTime == null){
            endTime = DateUtil.endOfDay(DateUtil.date());
        }
        switch(queryType){
            case "30d":
                startTime = DateUtil.beginOfDay(DateUtil.offsetDay(endTime,-29));
                break;
            case "sm":
                startTime = DateUtil.beginOfDay(DateUtil.offsetMonth(endTime,-5));
                break;
            case "7d":
                startTime = DateUtil.beginOfDay(DateUtil.offsetDay(endTime, -6));
                break;
            default:
                break;
        }
        qualityScreenPageVo.setStartTime(startTime);
        qualityScreenPageVo.setEndTime(endTime);

        List<Map<String,Object>> countLs = baseMapper.actualMeasureCountTop(qualityScreenPageVo);
        if(CollectionUtil.isEmpty(countLs)){
            //查询项目
            QueryWrapper<LinkappTenant> tenantQw = new QueryWrapper<>();
            tenantQw.isNotNull("project_amount");
            tenantQw.orderByDesc("project_amount");
            List<LinkappTenant> ls = tenantMapper.selectList(tenantQw);
            if (CollectionUtil.isNotEmpty(ls)) {
                ls.stream().forEach(t->{
                    Map<String,Object> mp = new HashMap<>();
                    mp.put("platformProjectName",t.getPlatformProjectName());
                    mp.put("num",0);
                    mp.put("okRate",0);
                    mp.put("actualTypeOkNum",0);
                    mp.put("actualTypeTotalNum",0);
                    countLs.add(mp);
                });

            }
        }
        return RestBuilders.successBuilder().data(countLs).build();
    }

    @Override
    public RestMessage mainIndexCount(QualityScreenPageVo qualityScreenPageVo) {
        EnterpriseQualityMainIndexCount mainIndexCount = new EnterpriseQualityMainIndexCount();
        Date now = DateUtil.date();
        Date ydStart = DateUtil.beginOfDay(DateUtil.offsetDay(now,-1));
        Date ydEnd = DateUtil.endOfDay(DateUtil.offsetDay(now,-1));
        Date tdStart = DateUtil.beginOfDay(now);
        Date tdEnd = DateUtil.endOfDay(now);

        int ydCheckNum = getQualityCheckNum(ydStart,ydEnd,false);
        int tdCheckNum = getQualityCheckNum(tdStart,tdEnd,false);
        int totalCheckNum = getQualityCheckNum(null,null,false);
        int okTotalCheckNum = getQualityCheckNum(null,null,true);

        mainIndexCount.setYesterdayCheckTotalNum(ydCheckNum);
        mainIndexCount.setTodayCheckTotalNum(tdCheckNum);
        mainIndexCount.setCheckTotalNum(totalCheckNum);
        if(totalCheckNum != 0){
            mainIndexCount.setCheckCloseReat(NumberUtil.div(okTotalCheckNum,totalCheckNum,4));
        }

        List<Map<String,Object>> mpLs = baseMapper.actualMeasureTypeCountAndRate();
        if(CollectionUtil.isNotEmpty(mpLs)){
            mpLs.stream().forEach(p->{
                int num = Integer.parseInt(p.get("num").toString());
                int actualTypeOkNum = Integer.parseInt(p.get("actualTypeOkNum").toString());
                int actualTypeTotalNum = Integer.parseInt(p.get("actualTypeTotalNum").toString());
                mainIndexCount.setActualCheckNum(num);
                if(actualTypeTotalNum != 0){
                    mainIndexCount.setActualOkRate(NumberUtil.div(actualTypeOkNum,actualTypeTotalNum,4));
                }
            });
        }


        int ydExceNum = getAppraisingExcellentNum(ydStart,ydEnd);
        int totalExceNum = getAppraisingExcellentNum(null,null);

        mainIndexCount.setYesterdayYxsgNum(ydExceNum);
        mainIndexCount.setTotalYxsgNum(totalExceNum);

        List<ProblemType> problemTypeList = getEnterpriseProblemTypes();

        mainIndexCount.setProblemTypeList(problemTypeList);


        return RestBuilders.successBuilder().data(mainIndexCount).build();
    }

    private List<ProblemType> getEnterpriseProblemTypes() {
        QueryWrapper<ProblemType> qw = new QueryWrapper<>();
        qw.isNull("tenant_id_");
        qw.eq("level_",1);
        qw.orderByAsc("id");
        List<ProblemType> ls = problemTypeMapper.selectList(qw);
        return ls;
    }

    /**
     * 获取优秀施工数量
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @return 数量
     */
    private int getAppraisingExcellentNum(Date startTime, Date endTime) {
        QueryWrapper<QualityAppraisingExcellent> qw = new QueryWrapper<>();
        qw.eq("delete_state",1);
        if(startTime != null && endTime != null){
            qw.between("create_time",startTime,endTime);
        }
        qw.inSql("tenant_id","select lt.id from linkapp_tenant lt");
        int excNum = qualityAppraisingExcellentMapper.selectCount(qw);
        return excNum;
    }

    /**
     * 获取质量检查数量
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @param okCheck
     * @return 数量
     */
    private int getQualityCheckNum(Date startTime, Date endTime,boolean okCheck) {
        QueryWrapper<QualityInspection> qiqw = new QueryWrapper<>();
        if(startTime != null && endTime != null){
            qiqw.between("create_time_",startTime,endTime);
        }
        qiqw.inSql("tenant_id_"," select id from linkapp_tenant ");
        int insNum = qualityInspectionMapper.selectCount(qiqw);
        QueryWrapper<QualityQuestionInfo> qqqw = new QueryWrapper<>();
        if(startTime != null && endTime != null) {
            qqqw.between("create_time", startTime, endTime);
        }
        //这里原设计是单表查询，现在因为要关联表查询了，懒得改，就这样吧
        qqqw.inSql("tenant_id","select id from linkapp_tenant");
        if(okCheck){
            qqqw.in("question_state",3);
        }
        int queNum = questionInfoMapper.selectCount(qqqw);
        return insNum + queNum;
    }

    /**
     * 同步实测实量分类
     * @param enterData 企业实测实量库
     * @param tenantData 项目实测实量库
     * @param tenant 租户信息
     * @param syncAdd 是否同步新增
     * @param syncUpdate 是否同步更新
     */
    private void syncActualTypeItem(List<ActualMeasureTypeDto> enterData, List<ActualMeasureTypeDto> tenantData, LinkappTenant tenant,boolean syncAdd, boolean syncUpdate) {
        //这是一个前置操作，实际是刷租户的历史分类的
        historyTypeItemFlushData(tenantData);

        //历史数据刷完后重新查询项目级数据
        ActualMeasureTypeVo paramVo = new ActualMeasureTypeVo();

        //项目级
        paramVo.setTenantId(tenant.getId());
        paramVo.setDeleteState(1);
        tenantData = baseMapper.selectTypeDtoList(paramVo);

        Date now = DateUtil.date();
        //key是原企业typeId
        Map<Long, ActualMeasureType> addTypeMp = new HashMap<>();
        List<ActualMeasureTypeDto> finalTenantData = tenantData;
        enterData.stream().forEach(ed -> {
            //1、删除的不同步
            //2、修改的，如果项目已用，不同步
            //3、新增的，插入

            Long enterpriseTypeId = ed.getId();
            //ActualMeasureTypeDto typeDto = tenantData.stream().filter(td -> td.getEnterpriseTypeId().equals(enterpriseTypeId)).findFirst().orElse(null);
            ActualMeasureTypeDto typeDto = finalTenantData.stream().filter(td -> {
                Long tdEnterpriseTypeId = td.getEnterpriseTypeId();
                if(tdEnterpriseTypeId != null && tdEnterpriseTypeId.equals(enterpriseTypeId)){
                    return true;
                }else{
                    return false;
                }
            }).findFirst().orElse(null);
            if (typeDto == null) {
                if(syncAdd){
                    log.info("实测实量分类原始id:{}--名称:{}新增的", ed.getId(), ed.getName());
                    /*if("zw测试1".equals(ed.getName())){
                        log.info("ssss", JSONUtil.toJsonStr(ed));
                    }*/
                    //新增的
                    ActualMeasureType actualMeasureType = initActualType(ed, tenant, addTypeMp.get(ed.getParentId()), now);
                    saveUpdateFullIdNoCheck(actualMeasureType);
                    addTypeMp.put(ed.getId(), actualMeasureType);

                    //保存算法
                    List<ActualMeasureItem> itemList = ed.getItemList();
                    if (CollectionUtil.isNotEmpty(itemList)) {
                        itemList.stream().forEach(at -> {
                            ActualMeasureItem actualMeasureItem = initActualItem(at, actualMeasureType, now);
                            actualMeasureItemMapper.insert(actualMeasureItem);
                        });
                    }
                }

            } else {
                ActualMeasureType dbActualType = new ActualMeasureType();
                BeanUtil.copyProperties(typeDto, dbActualType, CopyOptions.create().setIgnoreNullValue(true));
                //比较名称
                String oldName = typeDto.getName();
                String newName = ed.getName();
                if (StringUtils.isNotBlank(oldName) && StringUtils.isNotBlank(newName) && !oldName.equals(newName)) {
                    if(syncUpdate){
                        //修改了名称，需要查询是否被使用，这里本应该父级也不能变，后来讨论只对节点校验，所以可以增加层级判断不去查询是否有使用？
                        ActualMeasureItemVo itemParamVo = new ActualMeasureItemVo();
                        itemParamVo.setTenantId(tenant.getTenantId());
                        itemParamVo.setMeasureTypeId(typeDto.getId());
                        int useNum = actualMeasureItemMapper.selectUseInfoNum(itemParamVo);
                        if (useNum > 0) {
                            //已使用，不同步
                            log.info("实测实量分类id:{}--名称:{}已使用，不同步", typeDto.getId(), typeDto.getName());
                        } else {
                            //修改名称
                            dbActualType.setName(newName);
                            dbActualType.setModifier("同步");
                            dbActualType.setModifyTime(now);
                            saveUpdateFullIdNoCheck(dbActualType);

                            //还要修改fullName
                            //updateTypeFullName(dbActualType, oldName);
                            updateTypeFullNameIte(dbActualType, oldName, newName);
                        }
                    }
                }
                //addTypeMp.put(ed.getEnterpriseTypeId(), dbActualType);
                addTypeMp.put(ed.getId(), dbActualType);

                //判断算法存在，保存更新
                List<ActualMeasureItem> oldItemList = typeDto.getItemList();
                List<ActualMeasureItem> itemList = ed.getItemList();
                if (CollectionUtil.isNotEmpty(itemList)) {
                    itemList.stream().forEach(at -> {
                        Long enterpriseItemId = at.getId();
                        ActualMeasureItem item = oldItemList.stream().filter(td -> td.getEnterpriseItemId().equals(enterpriseItemId)).findFirst().orElse(null);
                        ActualMeasureItem actualMeasureItem = initActualItem(at, dbActualType, now);
                        if (item == null) {
                            if(syncAdd){
                                //新增算法
                                actualMeasureItemMapper.insert(actualMeasureItem);
                            }
                        } else {
                            if(syncUpdate){
                                ActualMeasureItemVo itemParamVo = new ActualMeasureItemVo();
                                itemParamVo.setTenantId(tenant.getTenantId());
                                itemParamVo.setId(item.getId());
                                int useNum = actualMeasureItemMapper.selectUseInfoNum(itemParamVo);
                                if (useNum > 0) {
                                    //已使用，不同步
                                    log.info("实测实量算法id:{}--名称:{}已使用，不同步", item.getId(), item.getItemName());
                                } else {
                                    BeanUtil.copyProperties(actualMeasureItem, item, CopyOptions.create().setIgnoreNullValue(true));
                                    item.setModifier("同步");
                                    item.setModifyTime(now);
                                    actualMeasureItemMapper.updateById(item);
                                }
                            }
                        }
                    });
                }
            }

        });

    }

    /**
     * 刷历史分类算法数据
     * @param tenantData 租户分类算法数据
     */
    private void historyTypeItemFlushData(List<ActualMeasureTypeDto> tenantData) {
        if(CollectionUtil.isNotEmpty(tenantData)){
            List<ActualMeasureTypeDto> delTypeLs = new ArrayList<>();
            Iterator<ActualMeasureTypeDto> it = tenantData.iterator();
            while(it.hasNext()){
                ActualMeasureTypeDto typeDto = it.next();
                Long enterpriseTypeId = typeDto.getEnterpriseTypeId();
                if(enterpriseTypeId == null){
                    ActualMeasureType at = new ActualMeasureType();
                    BeanUtil.copyProperties(typeDto,at,CopyOptions.create().setIgnoreNullValue(true));
                    String name = at.getName();
                    Integer itemType = at.getItemType();
                    QueryWrapper<ActualMeasureType> qw = new QueryWrapper<>();
                    qw.eq("name",name);
                    qw.eq("level",at.getLevel());
                    if(itemType != null){
                        qw.eq("item_type",itemType);
                    }
                    qw.isNull("tenant_id");
                    qw.orderByDesc("delete_state");
                    List<ActualMeasureType> ls = baseMapper.selectList(qw);
                    if(CollectionUtil.isNotEmpty(ls)){
                        ActualMeasureType entType = ls.get(0);
                        at.setEnterpriseTypeId(entType.getId());
                    }else{
                        //设置为删除
                        at.setDeleteState(0);
                        //tenantData.remove(typeDto);
                        //delTypeLs.add(typeDto);
                        it.remove();
                    }
                    baseMapper.updateById(at);
                }
                //算法
                List<ActualMeasureItem> itemList = typeDto.getItemList();
                if(CollectionUtil.isNotEmpty(itemList)){
                    Iterator<ActualMeasureItem> itemIt = itemList.iterator();
                    while (itemIt.hasNext()){
                        ActualMeasureItem item = itemIt.next();
                        Long enterpriseItemId = item.getEnterpriseItemId();
                        if(enterpriseItemId == null){
                            QueryWrapper<ActualMeasureItem> qw = new QueryWrapper<>();
                            qw.eq("item_name",item.getItemName());
                            qw.isNull("tenant_id");
                            qw.orderByDesc("delete_state");
                            List<ActualMeasureItem> itemLs = actualMeasureItemMapper.selectList(qw);
                            if(CollectionUtil.isNotEmpty(itemLs)){
                                ActualMeasureItem entItem = itemLs.get(0);
                                item.setEnterpriseItemId(entItem.getId());
                            }else{
                                item.setDeleteState(0);
                            }
                            actualMeasureItemMapper.updateById(item);
                        }
                    }

                }
            }

        }
    }

    /**
     * 更新分类，sql替换
     * @param dbActualType 分类
     * @param oldName 老名称
     */
    private void updateTypeFullName(ActualMeasureType dbActualType, String oldName) {
        String fullId = dbActualType.getFullId();
        //懒得写sql，就查出来修改吧
        ActualMeasureTypeVo paramVo = new ActualMeasureTypeVo();
        paramVo.setTenantId(dbActualType.getTenantId());
        paramVo.setFullId("/" + dbActualType.getId() + "/");
        paramVo.setOldName(oldName + "/");
        paramVo.setNewName(dbActualType.getName() + "/");
        paramVo.setModifyTime(dbActualType.getModifyTime());
        paramVo.setModifier(dbActualType.getModifier());
        int upNum = baseMapper.updateTypeFullName(paramVo);
        log.info("----执行条数：{}", upNum);
    }

    /**
     * 迭代更新fullName
     * @param dbActualType 分类
     * @param oldName 原始名称
     * @param newName 新名称
     */
    private void updateTypeFullNameIte(ActualMeasureType dbActualType, String oldName, String newName) {
        doUpdateTypeFullName(dbActualType,dbActualType,oldName,newName);
        Long id = dbActualType.getId();
        //懒得写sql，就查出来修改吧
        QueryWrapper qw = new QueryWrapper();
        qw.eq("parent_id", id);
        List<ActualMeasureType> ls = baseMapper.selectList(qw);
        if (CollectionUtil.isNotEmpty(ls)) {
            ls.stream().forEach(d -> {
                int upNum = doUpdateTypeFullName(d,dbActualType,oldName,newName);

                log.info("----更新数量：{}", upNum);
                Integer itemType = d.getItemType();
                if (itemType != 3) {
                    //有子集
                    updateTypeFullNameIte(d, oldName, newName);
                }
            });
        }
    }

    /**
     * 执行更新fullName
     * @param d 当前分类
     * @param parentType 父级分类
     * @param oldName 原名称
     * @param newName 新名称
     * @return 执行更新数量
     */
    private int doUpdateTypeFullName(ActualMeasureType d, ActualMeasureType parentType, String oldName, String newName) {
        String oldFullName = d.getFullName();
        oldFullName = oldFullName.replace(oldName + "/", newName + "/");
        d.setFullName(oldFullName);
        d.setModifier(parentType.getModifier());
        d.setModifyTime(parentType.getModifyTime());
        int upNum = baseMapper.updateById(d);
        return upNum;
    }

    /**
     * 初始化算法
     * @param at 算法
     * @param actualMeasureType 分类
     * @param now 时间
     * @return 算法对象
     */
    private ActualMeasureItem initActualItem(ActualMeasureItem at, ActualMeasureType actualMeasureType, Date now) {
        ActualMeasureItem d = new ActualMeasureItem();
        BeanUtil.copyProperties(at, d, CopyOptions.create().setIgnoreNullValue(true));
        d.setEnterpriseItemId(at.getId());
        d.setId(null);
        d.setMeasureTypeId(actualMeasureType.getId());
        d.setTenantId(actualMeasureType.getTenantId());
        d.setCreateTime(now);
        d.setModifyTime(now);
        d.setDeleteState(1);
        return d;
    }

    /**
     * 保存更新fullId不带检查
     * @param levelType 分类
     */
    private void saveUpdateFullIdNoCheck(ActualMeasureType levelType) {
        if(levelType.getId() == null){
            baseMapper.insert(levelType);
        }
        int level = levelType.getLevel();
        if (level == 1) {
            levelType.setFullId("/" + levelType.getId() + "/");
        } else {
            levelType.setFullId(levelType.getFullId() + levelType.getId() + "/");
        }
        baseMapper.updateById(levelType);
    }

    /**
     * 初始化分类
     * @param ed 企业级分类
     * @param tenant 租户
     * @param parentType 父级分类
     * @param now 时间
     * @return 租户分类
     */
    private ActualMeasureType initActualType(ActualMeasureTypeDto ed, LinkappTenant tenant, ActualMeasureType parentType, Date now) {
        ActualMeasureType t = new ActualMeasureType();
        BeanUtil.copyProperties(ed,t,CopyOptions.create().setIgnoreNullValue(true));
        Long oldMeasureTypeId = ed.getId();
        t.setId(null);
        t.setTenantId(tenant.getId());
        t.setCreateTime(now);
        t.setModifyTime(now);
        t.setDeleteState(1);
        t.setEnterpriseTypeId(oldMeasureTypeId);

        //找父级
        if (parentType != null) {
            t.setParentId(parentType.getId());
            t.setFullId(parentType.getFullId());
        } else {
            //说明是顶级
            t.setParentId(0L);
        }
        return t;
    }

    /**
     * 初始话分类保存
     * @param mp 分类map
     * @param linkappUser 租户
     */
    private void initActualMeasureTypeSave(Map<String, Object> mp, LinkappUser linkappUser) {
        Object level1Name = mp.get("一级");
        Object level2Name = mp.get("二级");
        Object level3Name = mp.get("三级");
        Object itemName = mp.get("测量内容");
        Object qualifiedStandard = mp.get("合格标准");
        Object unit = mp.get("单位");
        Object standardTypeObj = mp.get("标准");
        Object calPointNum = mp.get("计算点");
        Object groupCalPointNum = mp.get("每组计算点");
        Object breakingPointStandard = mp.get("爆点标准");
        Object measureMemo = mp.get("测量说明");
        Object algorithm = mp.get("算法");
        Object designValue = mp.get("设计值(Y/N)");

        ActualMeasureType level1Type = initActualMeasureType(level1Name, 1, linkappUser, null);
        saveUpdateFullId(level1Type);

        ActualMeasureType level2Type = initActualMeasureType(level2Name, 2, linkappUser, level1Type);
        saveUpdateFullId(level2Type);

        ActualMeasureType level3Type = initActualMeasureType(level3Name, 3, linkappUser, level2Type);
        saveUpdateFullId(level3Type);

        ActualMeasureItem actualMeasureItem = new ActualMeasureItem();
        actualMeasureItem.setItemName(itemName.toString());
        actualMeasureItem.setTenantId(level3Type.getTenantId());
        actualMeasureItem.setMeasureTypeId(level3Type.getId());
        actualMeasureItem.setQualifiedStandard(String.valueOf(qualifiedStandard));
        actualMeasureItem.setUnit(String.valueOf(unit));
        int standardType = 0;
        switch (String.valueOf(standardTypeObj)) {
            case "国标":
                standardType = 1;
                break;
            default:
                break;
        }
        actualMeasureItem.setStandardType(standardType);
        if (calPointNum != null) {
            actualMeasureItem.setCalPointNum(Integer.parseInt(calPointNum.toString()));
        }
        if (groupCalPointNum != null) {
            if (NumberUtil.isNumber(groupCalPointNum.toString())) {
                actualMeasureItem.setGroupCalPointNum(Integer.parseInt(groupCalPointNum.toString()));
            }
        }
        actualMeasureItem.setBreakingPointStandard(String.valueOf(breakingPointStandard));
        actualMeasureItem.setMeasureMemo(String.valueOf(measureMemo));
        if (algorithm != null) {
            actualMeasureItem.setAlgorithm(Integer.parseInt(algorithm.toString()));
        }
        actualMeasureItem.setDesignValue(String.valueOf(designValue));
        actualMeasureItem.setSortNo(1);
        actualMeasureItem.setCreator(linkappUser.getId().toString());
        actualMeasureItem.setModifier(actualMeasureItem.getCreator());
        actualMeasureItem.setCreateTime(DateUtil.date());
        actualMeasureItem.setModifyTime(actualMeasureItem.getCreateTime());
        actualMeasureItem.setDeleteState(1);

        QueryWrapper<ActualMeasureItem> qw = new QueryWrapper();
        qw.eq("delete_state", 1);
        qw.eq("tenant_id", actualMeasureItem.getTenantId());
        qw.eq("measure_type_id", actualMeasureItem.getMeasureTypeId());
        qw.eq("item_name", actualMeasureItem.getItemName());
        ActualMeasureItem item = actualMeasureItemMapper.selectOne(qw);
        if (item == null) {
            actualMeasureItemMapper.insert(actualMeasureItem);
        }

    }

    /**
     * 保存并更新fullid
     *
     * @param levelType 分类
     */
    private void saveUpdateFullId(ActualMeasureType levelType) {
        //先查询
        QueryWrapper<ActualMeasureType> qw = new QueryWrapper();
        qw.eq("delete_state", 1);
        qw.eq("full_name", levelType.getFullName());
        qw.eq("level", levelType.getLevel());
        qw.eq("tenant_id", levelType.getTenantId());
        ActualMeasureType inDbType = this.baseMapper.selectOne(qw);
        if (inDbType != null) {
            BeanUtil.copyProperties(inDbType, levelType, CopyOptions.create().setIgnoreNullValue(true));
        } else {
            this.baseMapper.insert(levelType);
            int level = levelType.getLevel();
            if (level == 1) {
                levelType.setFullId("/" + levelType.getId() + "/");
            } else {
                levelType.setFullId(levelType.getFullId() + levelType.getId() + "/");
            }
            this.baseMapper.updateById(levelType);
        }
    }

    /**
     * 初始分类
     *
     * @param levelName
     * @param level
     * @param linkappUser
     * @param parentType
     * @return
     */
    private ActualMeasureType initActualMeasureType(Object levelName, int level, LinkappUser linkappUser, ActualMeasureType parentType) {
        ActualMeasureType actualMeasureType = new ActualMeasureType();
        actualMeasureType.setTenantId(linkappUser.getTenantId());
        if (levelName == null) {
            return null;
        }
        actualMeasureType.setName(levelName.toString());
        if (level == 1) {
            actualMeasureType.setFullName(levelName + "/");
            actualMeasureType.setParentId(0L);
        } else {
            actualMeasureType.setFullName(parentType.getFullName() + levelName + "/");
            actualMeasureType.setFullId(parentType.getFullId());
        }

        if (parentType != null) {
            actualMeasureType.setParentId(parentType.getId());
        }
        actualMeasureType.setSortNo(1);
        actualMeasureType.setLevel(level);
        actualMeasureType.setCreator(linkappUser.getId().toString());
        actualMeasureType.setModifier(actualMeasureType.getCreator());
        actualMeasureType.setCreateTime(DateUtil.date());
        actualMeasureType.setModifyTime(actualMeasureType.getCreateTime());
        actualMeasureType.setDeleteState(1);

        return actualMeasureType;
    }

    @Override
    public ActualMeasureType getOneById(Serializable id) {
        return baseMapper.getOneById(id);
    }

    /**
     * 校验重复
     */
    private void validRepeat(ActualMeasureType appQualityActualMeasureType) {
        /* QueryWrapper<ActualMeasureType> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("name", appQualityActualMeasureType.getName());
        queryWrapper.eq("tenant_id", linkappUserContextProducer.getNotNullCurrent().getTenantId());
        List<ActualMeasureType> list = baseMapper.selectList(queryWrapper);
        if (list.size() == 0) {
            return;
        }
        if (list.size() > 1) {
            throw new BusinessException("名称有重复");
        }
        if (ObjectUtils.isEmpty(appQualityActualMeasureType.getId())) {
            throw new BusinessException("名称已存在");
        }
        if (!appQualityActualMeasureType.getId().equals(list.get(0).getId())) {
            throw new BusinessException("名称已存在");
        }
                    */

    }


    /**
     * 校验参数必填
     */
    private void validParamRequired(ActualMeasureType appQualityActualMeasureType) {
        //Assert.notNull(appQualityActualMeasureType, "参数为空");
        //Assert.isTrue(StringUtils.isNotBlank(appQualityActualMeasureType.getName()), "名称为空");
    }

    /**
     * 校验参数格式
     */
    private void validParamFormat(ActualMeasureType appQualityActualMeasureType) {
        //Assert.isTrue(appQualityActualMeasureType.getName() == null || appQualityActualMeasureType.getName().length() <= 50,
        //        "名称超长");
    }
}

